// 点击显示注册框
$("#goto-register").on('click', function () {
    $("#register").stop().show();
})

// 点击隐藏注册框
$("#goto-login").on('click', function () {
    $("#register").stop().hide();
})

// 点击注册
$("#register .layui-form").on('submit', function(ev){
    ev.preventDefault();
    let data = {
        username: $("#register input[name=username]").val(),
        password: md5($("#register input[name=password]").val())
    };
    let dataArr = [];
    for (key in data) {
        dataArr.push(key + '=' + data[key]);
    }
    let dataStr = dataArr.join('&');
    // 请求注册接口
    registerAPI(dataStr, (res) => {
        console.log(res)
    })
    return false;
})

// 点击登录
$("#login .layui-form").on('submit', function(ev){
    ev.preventDefault();
    let data = {
        username: $("#login input[name=username]").val(),
        password: md5($("#login input[name=password]").val())
    };
    let dataArr = [];
    for (key in data) {
        dataArr.push(key + '=' + data[key]);
    }
    let dataStr = dataArr.join('&');
    // 登陆接口
    loginAPI(dataStr, (res) => {
        window.location.href = './index.html';
        sessionStorage.setItem('token', res.data.token);
    })
    return false;
})